<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册页面</title>
    <style>
        *{
            margin: auto;
            padding: auto;
            box-sizing: border-box;
        }
        body{
            /*background: url("img/1570724147259.jpg") no-repeat center;*/
        }
        .bujv{
            width: 900px;
            height: 500px;
            border: 5px solid #eeeeee;
            background-color: white;
            margin: auto;
            margin-top: 100px;
        }
        .div1{
            /*border: 1px solid red;*/
            float: left;
            padding: 10px;
        }
        .div1 > .yi{
            color: #ffD026;
            font-size: 20px;
        }
        .div1 > .er{
            color: #A6A6A6;
            font-size: 20px;
        }
        .div2{
            /*border: 1px solid red;*/
            float: left;
            width: 450px;
            padding-top: 25px;
            padding-left: 30px;
        }

        .div3{
            /*border: 1px solid red;*/
            float: right;
            padding: 10px;
        }
        .div3 p{
            font-size: 10px;
        }
        .div3 p a{
            color: pink;
        }

        .zhi{
            width: 100px;
            text-align: right;
            height: 45px;
        }
        .kuang{
            padding-left: 50px;
        }
        #username,#password,#email,#name,#tel,#birthday,#yanzhengma{
            width: 251px;
            height: 32px;
            border: 1px solid #A6A6A6;
            /*  设置边框圆角  */
            border-radius: 5px;
            padding-left: 10px ;
        }
        #submit{
            width: 125px;
            height: 40px;
            background-color: #ffD026;
            border: 1px solid #ffD026;
            /*padding-left: 20px;*/
        }
        .submit{
            padding-left: 22px;
        }

        .error{
            color: red;
        }
    </style>



</head>
<body>

    <div class="bujv">
        <div class="div1">
            <p class="yi">新用户注册</p>
            <p class="er">USER REGISTER</p>
        </div>
        <div class="div2">
            <form action="#" method="get" id="form">
                <table>
                    <tr>
                        <td class="zhi"><label for="username">用户名</label></td>
                        <td class="kuang">
                            <input type="text" name="username" id="username" placeholder="请输入用户名">
                            <span id="s_username" class="error"></span>
                        </td>
                    </tr>
                    <tr>
                        <td class="zhi"><label for="password">密码</label></td>
                        <td class="kuang">
                            <input type="password" name="password" id="password" placeholder="请输入密码">
                            <span id="s_password" class="error"></span>
                        </td>
                    </tr>
                    <tr>
                        <td class="zhi"><label for="email">Email</label></td>
                        <td class="kuang"><input type="email" name="email" id="email"> </td>
                    </tr>
                    <tr>
                        <td class="zhi"><label for="name">姓名</label></td>
                        <td class="kuang"><input type="text" name="name" id="name"> </td>
                    </tr>
                    <tr>
                        <td class="zhi"><label for="tel">手机号</label></td>
                        <td class="kuang"><input type="text" name="tel" id="tel"> </td>
                    </tr>
                    <tr>
                        <td class="zhi">性别</td>
                        <td class="kuang">
                            <input type="radio" name="gender" value="male">男
                            <input type="radio" name="gender" value="female">女
                        </td>
                    </tr>
                    <tr>
                        <td class="zhi"><label for="birthday">出生日期</label></td>
                        <td class="kuang"><input type="date" name="birthday" id="birthday"> </td>
                    </tr>
                    <tr>
                        <td class="zhi"><label for="yanzhengma">验证码</label></td>
                        <td class="kuang"><input type="text" name="yanzhengma" id="yanzhengma"> </td>
                    </tr>
                    <tr>
                        <td colspan="2" align="center" class="submit"><input type="submit" value="注册" id="submit"> </td>
                    </tr>
                </table>
            </form>
        </div>
        <div class="div3">
            <P>
                已有账号
                <a href="#">立即登录</a>
            </P>
        </div>

    </div>

    <script>

        /*
            分析:
                1.给表单绑定 onsubmit 事件  监听器中判断每一种方法校验的结果
                    如果都为 true, 则监听器方法返回 true
                    如果有一个返回 false, 则监听器方法返回 false

                2.定义一些方法分别校验各个表单项
                3.给各个表单项绑定 onblur 事件

         */

        //页面加载完之后添加事件
        window.onload = function () {
            //给表单绑定 onsubmit 事件
            document.getElementById("from").onsubmit = function () {
                //调用用户校验方法   chkeUsername();
                //调用密码校验方法   chkePassword();
                //return chkeUsername() && chkePassword();

                return chkeUsername();
            }
            document.getElementById("username").onblur = chkeUsername();

        }

        //校验用户名
        function chkeUsername() {
            //获取用户名的值
            var username = document.getElementById("username").value;
            //定义正则表达式
            var reg_username = /^\w{6,12}$/;
            //判断值是否符合正则的规则
            var flag = reg_username.test(username);
            //提示信息
            var s_username = document.getElementById("s_username");
            if (flag) {
                //提示绿色文字
                alert("格式正确");
                s_username.innerHTML = "格式正确";
            } else {
                //提示红色文字
                alert("格式错误");
                s_username.innerHTML = "格式错误";
            }

            return flag;
        }

    </script>

</body>
</html>